/**
 * Created by Administrator on 2018/6/20.
 */
$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processs = res.data;
})
//查找项目中，产品经理 项目经理 等
$CertusJsonAjax.ajax("projMembersRole", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.projMemberInfo = res.data;
})

$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processCCBXTrace = res.data;
})

$CertusJsonAjax.ajax('bidBaseInfo', {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    // $$scope.file = {}
    // $$scope.classfictionselect = [
    //     {name: '内部保密', value: "0"},
    //     {name: '内部公开', value: "1"},
    //     {name: '完全公开', value: "2"},
    //     {name: '请选择', value: "xxxx"}
    // ];
    // $$scope.file.classfiction = "xxxx"
    // $$scope.rangeSelect = [
    //     {name: '请选择', value: "xxxx"},
    //     {name: '公司内部', value: "0"},
    //     {name: '公开信息', value: "1"}
    // ]
    // $$scope.file.range = "xxxx"
    $$scope.permissionSelect = [
        {name: '请选择', value: "xxxx"},
        {name: '总经理', value: "0"},
        {name: '总监', value: "1"},
        {name: '本部门', value: "2"}
    ]
    $$scope.file.permission = "xxxx"

    var picker2 = $('#datetime').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.file.validity = result;
            $$scope.$apply();
        }
    })

    $$scope.bid = res.data;
    $$scope.bid.processInstanceId = $CertusJsonAjax.getProInstanceId();
    $$scope.bid.stepInstanceId = $CertusJsonAjax.getStepInstanceId();
})

$$scope.shutdown = function () {
    $CertusJsonAjax.ajax("bidshutdown", $$scope.bid, function (res) {
        history.back();
    })
}

$$scope.formSubmitted = function () {
    if (certusValidateNotnull() && $$scope.bid.principalName && $$scope.bid.principalName != "" && $$scope.bid.specifiedMan && $$scope.bid.specifiedMan != "") {
        var regex = /[0-9a-zA-Z]*/g;
        var numList = $$scope.bid.principalName.match(regex);
        $CertusFormAjax.ajax("confirmUserId", {name: numList.join().replace(",", "")}, function (res) {
            if (res.data != "fail") {

                $$scope.bid.specifiedMan = res.data;
                $$scope.bid.pathFrom = "selbidA";
                $$scope.bid.nameOfPage = "商务方案";


                fileUpload($$scope, function (res) {
                    // $$scope.bid.specifiedMan = res.data;
                    $$scope.bid.uploadFilePath = res.data;
                    $$scope.bid.pathFrom = "selbidA";
                    $CertusJsonAjax.ajax("bidSubmit", $$scope.bid, function (res) {
                        history.back();
                    })
                }, function () {
                    $CertusJsonAjax.ajax("bidSubmit", $$scope.bid, function (res) {
                        history.back();
                    })
                }, $CertusFormAjax);
            } else {
                layer.msg("请包含正确工号");
            }
        })
    } else {
        layer.msg("请按照页面要求填写");
    }
}

var fileInstantiation = {
    classCateCode: 'NBCPYZ',
    fileClassCode: 'TBSWWD'
}
var fileInstantiationDisable = {
    classCateCodeDis: true, //文件类目不可修改
    fileClassCodeDis: true //文件类型不可修改
}
//调用初始化方法
initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $CertusFormAjax);

$$scope.formSubmitted = function () {

    $$scope.bid.nameOfPage = "商务方案";
    $$scope.bid.pathFrom = "selbidA";

    if (certusValidateNotnull()) {
        fileUpload($$scope, function (res) {
            $$scope.bid.uploadFilePath = res.data;
            $CertusJsonAjax.ajax("bidSubmit", $$scope.bid, function (res) {
                history.back();
            })
        }, function (res) {
            $CertusJsonAjax.ajax("bidSubmit", $$scope.bid, function (res) {
                history.back();
            })
        }, $CertusFormAjax)
    }


}

//文件上传统一字段
function showfile() {
    $(".hidefile").show();
}

function hidefile() {
    $$scope.file = {};
    initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $CertusFormAjax);
    $(".hidefile").hide();
}

function hidefile1() {
    if(certusValidateNotnullPolyfill()){
        $(".hidefile").hide();
    }
}



$$scope.getsssbbb = function(bb){
    if(bb == "starting"){
        return "正在进行中";
    }else if(bb == "denied"){
        return "否决";
    }else if(bb == "sentback"){
        return "被退";
    }else if(bb == "others"){
        return "关闭";
    }else if(bb == "completed"){
        return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
    return "待办";
}